﻿using System;
using System.Collections.Generic;
using System.Text;

namespace TuKu
{
    public static class Extensions
    {
        /// <summary>
        /// 扩展方法，检查非空
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static bool IsNotNullOrEmpty(this string s)
        {
            return !String.IsNullOrEmpty(s);
        }
        /// <summary>
        /// 扩展方法，显示信息
        /// </summary>
        /// <param name="s"></param>
        public static void showBox(this string s)
        {
            System.Windows.Forms.MessageBox.Show(s);
        }
        /// <summary>
        /// 扩展方法，获取文件扩名
        /// </summary>
        /// <param name="filename">文件名</param>
        /// <returns></returns>
        public static string getFileExtends(this string filename)
        {
            string ext = null;
            if (filename.LastIndexOf('.') > 0)
            {
                string[] fs = filename.Split('.');
                ext = fs[fs.Length - 1];
            }
            return ext;
        }
        /// <summary>
        /// 扩展方法，输出短日期格式
        /// </summary>
        /// <param name="s">2008-10-10 12:11:11</param>
        /// <returns>2008-10-10</returns>
        public static string toDateString(this string s)
        {
            return DateTime.Parse(s).ToString("yyyy-MM-dd");
        }
        /// <summary>
        /// 扩展方法，string转换int
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static int toInt(this string s)
        {
            int result = 0;
            if (!String.IsNullOrEmpty(s.ToString()))
            {
                result = int.Parse(s);
            }
            return result;
   
        }
        /// <summary>
        /// 扩展方法，转换成全拼
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static string toQuanPin(this string s)
        {
            return Common.Hz2Py.Convert(s);
        }
    }

}
